package cn.wolfcode.mp.service.impl;

import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.mapper.EmployeeMapper;
import cn.wolfcode.mp.qo.EmployeeQueryObject;
import cn.wolfcode.mp.service.IEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * mybatis-plus服务层接口实现类:
 * 1>自定义一个类EmployeeServiceImpl 继承ServiceImpl 实现自定义服务接口IEmployeeService
 * 2>在继承ServiceImpl上明确指定两个泛型
 *  1. 当前操作实体类对象对应mapper接口EmployeeMapper
 *  2. 当前操作实体对象Employee
 */
@Service
@Transactional
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> listByXmlSingle() {
        return employeeMapper.listByXmlSingle();
    }

    @Override
    public List<Employee> listByXmlJoin() {
        return employeeMapper.listByXmlJoin();
    }

    @Override
    public Page<Employee> queryPage(EmployeeQueryObject qo) {
        QueryWrapper<Employee> wrapper = new QueryWrapper<>();
        Page<Employee> page = new Page<>(qo.getCurrentPage(),qo.getPageSize());
        wrapper.like(StringUtils.hasText(qo.getKeyword()),"name",qo.getKeyword());
        //return employeeMapper.selectPage(page,wrapper);
        return super.page(page,wrapper);
    }
}
